package cn.com.infohold.smartcity.image;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.StateListDrawable;

import cn.com.infohold.smartcity.R;
import common.utils.ViewUtils;
import library.utils.DisplayUtil;


/**
 * Created by Mr.Fan on 2016-6-22.
 */
public class DrawableSelector {


    public static StateListDrawable getLoginButton(Context context) {
        StateListDrawable drawable = new StateListDrawable();
        float corner = context.getResources().getDimension(R.dimen.button_login_corner);
        GradientDrawable pressed = ViewUtils.getCornerDrawable(
                context.getResources().getColor(R.color.login_press), corner);
        GradientDrawable disable = ViewUtils.getCornerDrawable(
                context.getResources().getColor(R.color.login_disable), corner);
        GradientDrawable normal = ViewUtils.getCornerDrawable(
                context.getResources().getColor(R.color.login_normal), corner);
        drawable.addState(new int[]{android.R.attr.state_pressed}, pressed);
        drawable.addState(new int[]{-android.R.attr.state_enabled}, disable);
        drawable.addState(new int[]{android.R.attr.state_enabled}, normal);

        return drawable;
    }

    public static StateListDrawable getEditUnderBlue(Context context) {
        return getEditUnderline(context,
                context.getResources().getColor(R.color.white),
                context.getResources().getColor(R.color.ltgray),
                context.getResources().getColor(R.color.colorPrimary)
        );
    }

    public static StateListDrawable getEditUnderline(Context context, int bg, int lineNormal, int lineSelected) {
        StateListDrawable drawable = new StateListDrawable();

        Drawable[] ds_focused = new Drawable[]{
                new ColorDrawable(lineSelected),
                new ColorDrawable(bg)
        };
        LayerDrawable ld_focused = new LayerDrawable(ds_focused);
        ld_focused.setLayerInset(1, 0, 0, 0, (int) context.getResources().getDimension(R.dimen.line_0_75dp));

        Drawable[] ds_normal = new Drawable[]{
                new ColorDrawable(lineNormal),
                new ColorDrawable(bg)
        };
        LayerDrawable ld_normal = new LayerDrawable(ds_normal);
        ld_normal.setLayerInset(1, 0, 0, 0, (int) context.getResources().getDimension(R.dimen.line_0_75dp));

        drawable.addState(new int[]{android.R.attr.state_focused}, ld_focused);
        drawable.addState(new int[]{android.R.attr.state_enabled}, ld_normal);

        return drawable;
    }


    public static StateListDrawable getConfirmButton(Context context) {
        StateListDrawable drawable = new StateListDrawable();
        float corner = DisplayUtil.dp2px(2);
        GradientDrawable pressed = ViewUtils.getCornerDrawable(
                context.getResources().getColor(R.color.colorPrimaryDark), corner);
        GradientDrawable disable = ViewUtils.getCornerDrawable(
                context.getResources().getColor(R.color.colorPrimaryLight), corner);
        GradientDrawable normal = ViewUtils.getCornerDrawable(
                context.getResources().getColor(R.color.colorPrimary), corner);
        drawable.addState(new int[]{android.R.attr.state_pressed}, pressed);
        drawable.addState(new int[]{-android.R.attr.state_enabled}, disable);
        drawable.addState(new int[]{android.R.attr.state_enabled}, normal);

        return drawable;
    }


    public static StateListDrawable getResetButton(Context context) {
        StateListDrawable drawable = new StateListDrawable();
        float corner = DisplayUtil.dp2px(2);
        GradientDrawable pressed = ViewUtils.getCornerDrawable(Color.parseColor("#bbbbbb"), corner);
        GradientDrawable disable = ViewUtils.getCornerDrawable(Color.parseColor("#dddddd"), corner);
        GradientDrawable normal = ViewUtils.getCornerDrawable(Color.parseColor("#cccccc"), corner);
        drawable.addState(new int[]{android.R.attr.state_pressed}, pressed);
        drawable.addState(new int[]{-android.R.attr.state_enabled}, disable);
        drawable.addState(new int[]{android.R.attr.state_enabled}, normal);

        return drawable;
    }
}
